# coding=utf-8

from parsers.parser import Parser
from lxml import etree


class XPathParser(Parser):
    def __init__(self, parse_content):
        super(XPathParser, self).__init__()
        self.parse_content = parse_content

    def _inner_parse(self, response):
        # html_doc = response.content.decode("utf-8")
        html_doc = response.content
        tree = etree.HTML(html_doc)
        metadata = {"url": response.url, "status_code": response.status_code, "text": response.text, "encoding": response.encoding}
        # if response.status_code != 200:
        #     metadata["text"] = response.text
        item = self.parse_content(tree, metadata)
        return item
